#define _CRT_SECURE_NO_WARNINGS 1
#include "Heap.h"
void HeapTest()
{
	Heap hp;
	//ѵĳʼ
	HeapInit(&hp);
	int arr[] = { 8,2,5,10,1,6,3,7,4,9 };
	int sz = sizeof(arr) / sizeof(HPDateType);
	for (int i = 0; i < sz; i++)
	{
		HeapPush(&hp, *(arr+i));
	}
	while (!HeapEmpty(&hp))
	{
		printf("%d ", HeapTop(&hp));
		HeapPop(&hp);
	}
	printf("\n");
	//ѵ
	HeapDestroy(&hp);
}
void HeapSort(int* arr, int size)
{
	/*for (int i = 0; i < size; i++)
	{
		AdjestUp(arr, i);
	}*/
	for (int i = (size-1-1)/2; i >= 0; i--)
	{
		AdjestDown(arr, i, size);
	}
	int end = size - 1;
	while (end)
	{
		Swap(arr, arr + end);
		AdjestDown(arr, 0, end);
		end--;
	}
}
void PrintArr(int* arr, int size)
{
	for (int i = 0; i < size; i++)
	{
		printf("%d ", *(arr + i));
	}
	printf("\n");
}
void HeapSortTest()
{
	int arr[] = { 8,2,5,10,1,6,3,7,4,9 };
	int sz = sizeof(arr) / sizeof(HPDateType);
	PrintArr(arr, sz);
	HeapSort(arr, sz);
	PrintArr(arr, sz);
}

int main()
{
	//HeapTest();
	HeapSortTest();
	return 0;
}